//
//  CheckViewController.m
//  SafPay
//
//  Created by 贺庆博 on 2018/6/19.
//  Copyright © 2018年 ebo. All rights reserved.
//

#import "CheckViewController.h"
#import "SetPwdController.h"
#import "XXLinkLabel.h"
#import "ImportWalletController.h"
#import "ProperyController.h"
@interface CheckViewController ()
{
    BOOL isAgree;
}
@property (weak, nonatomic) IBOutlet XXLinkLabel *protocolLab;
@property (weak, nonatomic) IBOutlet UILabel *importLab;
@property (weak, nonatomic) IBOutlet UITextView *ruleTextView;
@property (strong, nonatomic)  NSMutableArray *messageModels;

@end

@implementation CheckViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    isAgree = YES;
    self.messageModels = [NSMutableArray array];
    for (int i = 0; i < 2; i++) {
        XXLinkLabelModel *messageModel = [[XXLinkLabelModel alloc]init];

        if (i == 0) {
            messageModel.message = @"我已经仔细阅读并同意";
            messageModel.image = kImageName(@"icon_agree");
            messageModel.imageShowSize = CGSizeMake(18, 18);
        }
        if (i == 1) {
            messageModel.message = @"服务及隐私条款";
            messageModel.imageClickBackStr =@"服务及隐私条款";
            messageModel.extend = @1;
        }
        [self.messageModels addObject:messageModel];
        
    }
    NSMutableDictionary * dic=[NSMutableDictionary dictionary];
    dic[NSForegroundColorAttributeName]=rgb(33,177,227);
    dic[NSFontAttributeName]= kFONT(14);
    self.protocolLab.messageModels = self.messageModels;
    self.protocolLab.imageClickBlock = ^(XXLinkLabelModel *linkInfo) {
        self->isAgree = !self->isAgree;
        linkInfo.image = self->isAgree?kImageName(@"icon_agree"):kImageName(@"icon_unagree");
        self.protocolLab.messageModels = self.messageModels;
    };
    self.protocolLab.labelClickedBlock = ^(id extend) {
        ProperyController *vc=[ProperyController new];
        [self.navigationController pushViewController:vc animated:YES];
    };
    
    NSMutableAttributedString *importAttri = [[NSMutableAttributedString alloc] initWithString:self.importLab.text];
    [importAttri addAttributes:dic range:[self.importLab.text rangeOfString:@"导入钱包＞＞"]];
    self.importLab.attributedText = importAttri;
    
    
    NSMutableAttributedString *ruleAttri = [[NSMutableAttributedString alloc]initWithData:[@"<span style=\"color:#9f9f9f\"><span style=\"color:#21b1e3\">•</span> 管家云银包通过您的密钥进行钱包管理，请妥善保管您的密钥。<br><span style=\"color:#21b1e3\">•</span> APP重新安装或更换收集后，可以通过密钥恢复您的钱包。<br><span style=\"color:#21b1e3\">•</span> 为了防止密钥丢失，请开启后尽快绑定您的手机或邮箱。</span>" dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
    [ruleAttri addAttributes:@{NSFontAttributeName:kFONT(14)} range:NSMakeRange(0, ruleAttri.length)];
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:6];
    [ruleAttri addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [ruleAttri length])];
    self.ruleTextView.attributedText = ruleAttri;
    
}
- (IBAction)btnClick:(id)sender {
    if(isAgree){
        [self.navigationController pushViewController:[SetPwdController  new] animated:YES
         ];
    }else{
        
         [MBProgressHUD showErrorWithText:@"请先同意服务及隐私条款"];
    }

}
- (IBAction)importClick:(id)sender {
    if(isAgree){
        
        [self.navigationController pushViewController:[ImportWalletController  new] animated:YES
         ];
    }else{
        
        [MBProgressHUD showErrorWithText:@"请先同意服务及隐私条款"];
    }
 
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.translucent = YES;
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    self.navigationController.navigationBar.translucent = NO;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
